from copy import deepcopy
class delaydata_bar:
    def __init__(self,args=[],delay=1):
        self.timekey=None
        self.predata=[]
        self.args=args
        self.delay=delay
    def oncalc(self,b,timekey=None):
        rst=[]
        if len(self.predata)==self.delay:
            rst=deepcopy(self.predata[0])
        else:
            for i in self.args:
                rst.append(None)
        isnoretime = True
        t = []
        for i in self.args:
            if i in b.keys():
                t.append(b[i])
            else:
                t.append(None)
        if timekey:
            if self.timekey == self.timekey:
                self.predata[-1] = t
                isnoretime = False
        if isnoretime:
            if len(self.predata) == self.delay:
                self.predata.pop(0)
            self.predata.append(t)
        self.timekey = timekey
        if len(rst)==1:
            rst=rst[0]
        return rst